package com.wctj.api.base;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

public abstract class BaseController {

    private static final String SUCCESS = "SUCCESS";

    protected static ResponseEntity<Result> ok() {
        Result result = new Result();
        result.setCode(HttpStatus.OK.value());
        result.setMsg(SUCCESS);
        return ResponseEntity.ok(result);
    }

    protected static <T> ResponseEntity<Result> ok(T t) {
        Result result = new Result();
        result.setCode(HttpStatus.OK.value());
        result.setMsg(SUCCESS);
        result.setData(t);
        return ResponseEntity.ok(result);
    }
    protected static <T> ResponseEntity<Result<T>> okG(T t) {
        Result result = new Result();
        result.setCode(HttpStatus.OK.value());
        result.setMsg(SUCCESS);
        result.setData(t);
        return ResponseEntity.ok(result);
    }

    protected static <T> ResponseEntity<Result> ok(HttpStatus httpStatus, T t) {
        Result result = new Result();
        result.setCode(httpStatus.value());
        result.setData(t);

        return ResponseEntity.ok(result);
    }
    protected static <T> ResponseEntity<Result<T>> okG(HttpStatus httpStatus, T t) {
        Result result = new Result();
        result.setCode(httpStatus.value());
        result.setData(t);
        return ResponseEntity.ok(result);
    }

    protected static <T> ResponseEntity<Result<T>> success(T t) {
        Result result = new Result();
        result.setCode(HttpStatus.OK.value());
        result.setMsg(SUCCESS);
        result.setData(t);
        return ResponseEntity.ok(result);
    }

    protected static <T> ResponseEntity<Result<T>> success(HttpStatus httpStatus, T t) {
        Result result = new Result();
        result.setCode(httpStatus.value());
        result.setData(t);
        return ResponseEntity.ok(result);
    }

    protected static ResponseEntity<Result> fail() {
        Result result = new Result();
        result.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
        result.setMsg(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(result);
    }

    protected static ResponseEntity fail(String msg) {
        Result result = new Result();
        result.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
        result.setMsg(msg);
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(result);
    }

    protected static <T> ResponseEntity<Result> fail(T data, String msg) {
        Result result = new Result();
        result.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
        result.setData(data);
        result.setMsg(msg);
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(result);
    }

}
